﻿using System;
using System.Globalization;

namespace BaseSet.Entity.Common.DataOperation
{
    /// <summary>
    /// 日期时间辅助类
    /// </summary>
    public class DateTimeHelper
    {
        /// <summary>
        /// 获取某年中某个月的最后一天
        /// </summary>
        /// <param name="date">含指定年月的日期</param>
        /// <returns>指定年月最后一天的长日期表示</returns>
        public static string  GetDateOfLastDay(DateTime date)
        {
            int totalDays = DateTime.DaysInMonth(date.Year, date.Month);

            string result = date.ToString("yyyy-MM-") + totalDays;
            return result;
        }

        /// <summary>
        /// 根据日期获取星期几的中文表示
        /// </summary>
        /// <param name="date">日期</param>
        /// <param name="formater">格式化字符串（如：“周ddd”、“星期ddd”、“礼拜ddd”，ddd必须带 将被替换为具体的中文数字）</param>
        /// <returns>返回星期几</returns>
        public static string GetWeekDayCN(DateTime date, string formater)
        {
            CultureInfo provider = new CultureInfo("zh-cn");

            string result = date.ToString(formater, provider);
            return result;
        }

        /// <summary>
        /// 获取指定日期的季度
        /// </summary>
        /// <param name="dt">指定日期</param>
        /// <returns></returns>
        public static int GetQuarter(DateTime dt)
        {
            int mNum = dt.Month;
            if ((dt.Month - 1) % 3 == 2)
            {
                mNum--;
            }
            return mNum / 3 + 1;
        }
    }
}